package com.pactera.miyuangroup.controller.web;

import java.util.List;

import com.pactera.miyuangroup.filter.CurrentUser;
import com.pactera.miyuangroup.vo.convertor.MenuConvert;
import com.pactera.miyuangroup.vo.request.VoidRequest;
import com.pactera.miyuangroup.vo.response.web.MenuRes;
import com.pactera.miyuangroup.vo.response.web.TreeMenuRes;
import com.pactera.miyuangroup.vo.response.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.pactera.miyuangroup.service.MenuService;
import com.pactera.miyuangroup.vo.response.ResultModel;


/**
 * 系统菜单controller
 */
@Api(description = "系统菜单")
@RestController
@RequestMapping("menu")
@Slf4j
public class MenuController {

    @Autowired
    private MenuService menuService;
    @Autowired
    private MenuConvert menuConvert;

    /**
     * 查询系统菜单
     *
     * @param @return
     * @throws
     * @Description:
     * @date 2018年4月17日 下午5:16:02
     * @author 陈浩
     */
    @ApiOperation(value = "查询系统菜单集合", notes = "查询系统菜单集合")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ResultModel<List<MenuRes>> selectMenuList(@RequestBody VoidRequest req) {
        log.info("调用查询系统菜单接口");
        List<MenuRes> menuList = menuConvert.convert2MenuRes(menuService.selectList(null));
        return ResultModel.ok(menuList);
    }


    /**
     * 查询系统菜单树形结构
     *
     * @param @return
     * @throws
     * @Description:
     * @date 2018年4月17日 下午5:16:02
     * @author 陈浩
     */
    @ApiOperation(value = "查询系统菜单树形结构", notes = "查询系统菜单树形结构")
    @RequestMapping(value = "/tree/list", method = RequestMethod.POST)
    public ResultModel<List<TreeMenuRes>> selectTreeMenuList(@RequestBody VoidRequest req) {
        log.info("调用查询系统菜单接口");
        List<TreeMenuRes> menuList = menuService.getTreeMenuList("");
        return ResultModel.ok(menuList);
    }

    /**
     * 查询用户菜单树形结构
     *
     * @param @return
     * @throws
     * @Description:
     * @date 2018年4月17日 下午5:16:02
     * @author 陈浩
     */
    @ApiOperation(value = "查询用户菜单", notes = "查询用户菜单信息")
    @RequestMapping(value = "/tree/user", method = RequestMethod.POST)
    public ResultModel<List<TreeMenuRes>> selectUserTreeMenuList(@CurrentUser User user, @RequestBody VoidRequest req) {
        log.info("调用查询用户菜单接口");
        List<TreeMenuRes> menuList = menuService.getTreeMenuList(user.getId());
        return ResultModel.ok(menuList);
    }


    /**
     * 查询角色对应菜单
     *
     * @param @return
     * @throws
     * @Description:
     * @date 2018年4月17日 下午5:16:02
     * @author 陈浩
     */
    @ApiOperation(value = "查询角色对应菜单", notes = "查询角色对应菜单信息")
    @ApiImplicitParams({@ApiImplicitParam(value = "角色ID", name = "roleId", required = true, paramType = "path")})
    @RequestMapping(value = "/tree/role/{roleId}", method = RequestMethod.GET)
    public ResultModel<List<MenuRes>> selectRoleMenuList(@PathVariable String roleId) {
        log.info("调用查询角色菜单接口");
        List<MenuRes> menuList = menuService.getMenuByRoleId(roleId);
        return ResultModel.ok(menuList);
    }

}
